package com.egao.common.module.cms.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.egao.common.component.elasticsearch.entity.ElasticSearchConstants;
import com.egao.common.core.exception.BusinessException;
import com.egao.common.core.exception.ParameterException;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.module.cms.entity.SelectedColumn;
import com.egao.common.module.cms.entity.SelectedColumn;
import com.egao.common.module.cms.entity.SelectedColumn;
import com.egao.common.module.cms.entity.vo.SelectedColumnListVO;
import com.egao.common.module.cms.mapper.SelectedColumnMapper;
import com.egao.common.module.cms.mapper.SelectedColumnMapper;
import com.egao.common.module.cms.service.SelectedColumnService;
import com.egao.common.module.cms.service.SelectedColumnService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (SelectedColumn)表服务实现类
 *
 * @author makejava
 * @since 2021-04-26 13:50:36
 */
@Service
public class SelectedColumnServiceImpl  extends ServiceImpl<SelectedColumnMapper, SelectedColumn> implements SelectedColumnService {



    @Override
    public List<SelectedColumnListVO> listPage(PageParam<SelectedColumnListVO> pageParam) {
        return baseMapper.listPage(pageParam);
    }

    @Override
    public JsonResult insertSelectedColumn(SelectedColumn selectedColumn) {
        if (selectedColumn == null) {
            throw new ParameterException("参数对象为空");
        }

        if (StrUtil.isBlank(selectedColumn.getTitle())) {
            throw new ParameterException("标题不能为空");
        }

        save(selectedColumn);
        return JsonResult.ok("添加成功");
    }

    @Override
    public JsonResult updateSelectedColumn(SelectedColumn SelectedColumn) {
        if (SelectedColumn == null) {
            throw new ParameterException("参数对象为空");
        }

        if (StrUtil.isBlank(SelectedColumn.getTitle())) {
            throw new ParameterException("标题不能为空");
        }

        updateById(SelectedColumn);
        return JsonResult.ok("修改成功");
    }

    @Override
    public JsonResult deleteSelectedColumn(Integer id) {
        if (id == null) {
            throw new ParameterException("参数对象为空");
        }

        if (removeById(id)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

    @Override
    public JsonResult getId(Integer id) {
        SelectedColumn selectedColumn = getSelectedColumnById(id);
        return JsonResult.ok().setData(selectedColumn);
    }

    @Override
    public SelectedColumn getSelectedColumnById(Integer id) {
        if (id == null) {
            throw new ParameterException("参数对象为空");
        }

        SelectedColumn selectedColumn = baseMapper.selectById(id);

        if (selectedColumn == null) {
            throw new BusinessException("参数对象为空");
        }
        return selectedColumn;
    }
}
